# coding: utf-8

from redis import StrictRedis

REDIS_HOST = 'r-uf62e134a0c68014.redis.rds.aliyuncs.com'
REDIS_PORT = 6379
REDIS_AUTH = 'G3EsmjZ6ULW9p4Zw'
REDIS_DB = 3

redis = StrictRedis(
    host=REDIS_HOST,
    port=REDIS_PORT,
    password=REDIS_AUTH,
    db=REDIS_DB
)
key = 'user:6000039'
# print(redis.zcount(key, 1, -1))
users = redis.zrange(key, 0, -1, True, True)
print(users)
# print(str(543718).encode() in users)

# print(redis.type('alist_6000039'))
#
# print(redis.smembers('alist_6000039'))
# print(redis.sismember('alist_6000039', 5101822))
# MAX_RECOMMEND_QUEUE_NUM = 60
# # redis.zadd('test1', {122222222222: '0.33333333333', 111111: 0.2222222222, 11111: 0.1222222222222222})
# value_dict = {542979: -0.010825630277395248, 541444: 0.07357856631278992, 542725: -0.03127797693014145, 540424: 0.14113132655620575, 538377: -0.010982951149344444, 543245: 0.217294842004776, 544015: 0.07207196205854416, 542994: -0.05826134607195854, 542999: -0.0013455301523208618, 538905: 0.20234203338623047, 541211: -0.009390337392687798, 538141: 0.009924223646521568, 543518: 0.04311475157737732, 543263: 0.030001334846019745, 543521: -0.010605193674564362, 542499: 0.3193209767341614, 543012: 0.13663631677627563, 543526: 0.08929486572742462, 541482: 0.0506913959980011, 543788: 0.03717378154397011, 538414: 0.17473207414150238, 542516: 0.01620600000023842, 539701: -0.05959787219762802, 541240: -0.0022017713636159897, 542265: -0.0595972016453743, 461627: -0.024887889623641968, 532286: 0.10015622526407242, 543669: 0.09103083610534668, 541249: 0.0006941799074411392, 543298: -0.010032368823885918, 542020: 0.1816900074481964, 542533: 0.10698188841342926, 535110: -0.04187258332967758, 518796: -0.05959799140691757, 540494: 0.12688632309436798, 538962: 0.043347395956516266, 543203: 0.5253629088401794, 452185: -0.02488578110933304, 543583: -0.04334690049290657, 475835: -0.05959804356098175, 536294: 0.0052263736724853516, 536209: 0.005226390436291695, 543889: 0.0385160818696022, 540009: 0.02706305682659149, 541548: 0.09969234466552734, 543600: 0.04813755303621292, 529522: 0.009924259968101978, 542835: 0.12083971500396729, 542068: 0.07733282446861267, 543862: 0.16067592799663544, 541801: -0.02665819227695465, 543608: 0.5253533124923706, 542078: 0.15721112489700317, 542082: 0.005224244669079781, 541334: 0.005224250257015228, 526729: 0.009924270212650299, 541579: -0.009390445426106453, 543123: -0.0571957565844059, 543629: 0.06042616814374924, 543633: 0.10739623755216599, 541843: 0.05275219678878784, 541590: -0.009390430524945259, 540059: 0.09487484395503998, 542622: 0.12861007452011108, 533663: 0.009924164041876793, 543395: 0.08353667706251144, 541350: 0.096406951546669, 541355: 0.27218836545944214, 543150: -0.010032806545495987, 543408: 0.5253589153289795, 542643: 0.0948747992515564, 539572: 0.005224248394370079, 531893: 0.009924214333295822, 543415: 0.5253565311431885, 540600: 0.029955517500638962, 541855: 0.008782558143138885, 542366: 0.05860478803515434, 541120: 0.11208707839250565, 541637: 0.0884857177734375, 538830: 0.038220297545194626, 543440: 0.10817882418632507, 542162: -0.059217117726802826, 541774: 0.08308325707912445, 540635: 0.09487472474575043, 542546: -0.032185498625040054, 542431: 0.8241102695465088, 539104: 0.0052263084799051285, 542178: 0.08633704483509064, 541155: 0.026312904432415962, 538949: 0.040598440915346146, 466925: -0.02488783746957779, 529149: -0.059597380459308624, 541680: 0.009924103505909443, 541310: 0.28297221660614014, 528886: 0.005210345610976219, 534775: -0.02488519251346588, 542968: 0.1651504635810852, 541437: 0.2721802890300751, 540926: 0.1805092841386795, 539349: -0.02488485351204872}
# values = []
# for (key, value) in value_dict.items():
#     values.append(value)
#     values.append(key)

# user_key = 'test1'
# print(values)
# redis.zadd('test1', *values)
#
# l = redis.zrange('test1', 0, -1, desc=True, withscores=True)
# for i in l:
#     print(i)


# def remove():
#     count = redis.zcard(user_key)
#     print('count: %s' % count)
#     if count <= MAX_RECOMMEND_QUEUE_NUM:
#         return
#     all_values = redis.zrange(user_key, 0, -1, True)
#     print(len(all_values))
#     if len(all_values) <= MAX_RECOMMEND_QUEUE_NUM:
#         return
#     rem_value_bytes = all_values[MAX_RECOMMEND_QUEUE_NUM:]
#     # rem_values = [int(v) for v in rem_value_bytes]
#     print(rem_value_bytes)
#     print(redis.zrem(user_key, *rem_value_bytes))
#
#
# remove()
